Skip to content

C++: Explain converted constants in comparison alerts - #23202

Open
SkyCipherr wants to merge 1 commit into
github:mainfrom
SkyCipherr:codex/explain-converted-comparison-constants
Open

SkyCipherr wants to merge 1 commit into
github:mainfrom
SkyCipherr:codex/explain-converted-comparison-constants

Conversation

@SkyCipherr

Copy link
Copy Markdown
Contributor

When a constant operand changes value during integral conversion, include the converted value in the cpp/constant-comparison alert. In the reduced libarchive example, the message now explains that the constant on the right evaluates to -1, in addition to reporting the inferred bound on the left.

Added regression cases for a converted constant on each side and for a value-preserving conversion. Both tests in the PointlessComparison suite pass. The comparison against the original query on the same fixtures showed the same 56 findings, with wording changes limited to the two new value-changing conversion cases.

Fixes #11744.

@SkyCipherr
SkyCipherr requested a review from a team as a code owner November 23, 2026 06:11
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Parenthesized casts bypass integral-conversion detection, causing alerts to lose the -1 explanation; the query needs to handle trailing parentheses and add a regression case.

1 open issue
What changed in this PR

This PR improves cpp/constant-comparison alerts by explaining converted constant values alongside inferred operand bounds, addressing the unclear diagnostics in #11744.

Changes:

  • Adds converted-value explanations for constant operands on either side of a comparison.
  • Adds regression cases for value-changing and value-preserving conversions.
  • Updates query help and adds a release note.
File Description
cpp/​ql/​test/​query-tests/​Likely Bugs/​Arithmetic/​PointlessComparison/​PointlessComparison.expected Records expected alerts for the new regression cases.
cpp/​ql/​test/​query-tests/​Likely Bugs/​Arithmetic/​PointlessComparison/​ConvertedConstants.c Tests conversions on both sides and an unchanged constant value.
cpp/​ql/​src/​Likely Bugs/​Arithmetic/​PointlessComparison.ql Adds converted constant values to alert explanations.
cpp/​ql/​src/​Likely Bugs/​Arithmetic/​PointlessComparison.qhelp Documents the explanation and corrects the comparison example.
cpp/​ql/​src/​change-notes/​2026-11-23-constant-comparison-conversions.md Announces the diagnostic improvement.

Review effort: Balanced (adaptive)

Comment on lines +25 to +26
operand.getUnconverted().getValue() !=
operand.getFullyConverted().(IntegralConversion).getValue()

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explanation of ”Comparison result is always the same“ in PR is technically correct, but unclear

2 participants